/*
 * MessageQueue.cpp
 *
 *  Created on: 2012-12-18
 *      Author: yangentao@gmail.com
 */

#include "MessageQueue.h"

namespace yet {

MessageQueue::MessageQueue() {

}
MessageQueue::~MessageQueue() {
	clear();
}
void MessageQueue::push_back(Message value) {
	AutoLock lock(this);
	msgQueue.push_back(value);
//	event.notify();
}
void MessageQueue::push_front(Message value) {
	AutoLock lock(this);
	msgQueue.push_front(value);
//	event.notify();
}
Message MessageQueue::pop_back() {
	if (isEmpty()) {
		throw EmptyQueueException();
	}
	AutoLock lock(this);
	Message msg = msgQueue.back();
	msgQueue.pop_back();
	return msg;
}
Message MessageQueue::pop_front() {
	if (isEmpty()) {
		throw EmptyQueueException();
	}
	AutoLock lock(this);
	Message msg = msgQueue.front();
	msgQueue.pop_front();
	return msg;
}
void MessageQueue::clear() {
	AutoLock lock(this);
	msgQueue.clear();
}

bool MessageQueue::isEmpty() {
	AutoLock al(this);
	return msgQueue.empty();
}
//void MessageQueue::quitWait(){
//	AutoLock lock(this);
//	event.notify();
//}
//bool MessageQueue::waitMessage(Message& msg, DWORD milliSeconds){
//	event.wait(milliSeconds);
//	if(isEmpty()){
//		return false;
//	}
//	msg =  pop_front();
//	return true;
//}
}

